package eu.telecombretagne.rsm.gui.frames.panels;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.JComboBox;
import javax.swing.JPanel;

import eu.telecombretagne.rsm.gui.NameConsts;

public class EffectsPanel extends JPanel {
	
	private static final long serialVersionUID = 6385878713564360014L;
	
	private JComboBox<String> effectsList;
	
	/**
	 * The constructor of the EffectsPanel.
	 */
	public EffectsPanel(){
		setLayout(new GridLayout(1, 3));
		
		String[] effectStrings = {NameConsts.NOEFFECTS, NameConsts.LOSS50, NameConsts.DUPLICATION50};
		
		effectsList = new JComboBox<String>(effectStrings);
		effectsList.setBackground(Color.white);
		effectsList.setSelectedIndex(0);
		
		add(effectsList);
	}
	
	/**
	 * Checks if none effects are enabled.
	 * @return Returns <i>true</i> if none effects are enabled and <i>false</i> otherwise.
	 */
	public Boolean isNoneEnabled(){
		String selection = (String) effectsList.getSelectedItem();
		return selection.equals(NameConsts.NOEFFECTS);
	}
	
	/**
	 * Checks if loss effects are enabled.
	 * @return Returns <i>true</i> if loss effects are enabled and <i>false</i> otherwise.
	 */
	public Boolean isLossEnabled(){
		String selection = (String) effectsList.getSelectedItem();
		return selection.equals(NameConsts.LOSS50);
	}
	
	/**
	 * Checks if duplication effects are enabled.
	 * @return Returns <i>true</i> if duplication effects are enabled and <i>false</i> otherwise.
	 */
	public Boolean isDuplicationEnabled(){
		String selection = (String) effectsList.getSelectedItem();
		return selection.equals(NameConsts.DUPLICATION50);
	}
	
	@Override
	public void setEnabled(boolean pEnabled){
		Component[] components = this.getComponents();
		
		for(int i = 0; i < components.length; i++){
			components[i].setEnabled(pEnabled);
		}
	}
}